package org.openclinic.web.context;

import javax.servlet.http.HttpServletRequest;

import org.openclinic.domain.User;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

public class AttributeRetriever {

	public static User getUserFromSession() {
		ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
		if (servletRequestAttributes == null) {
			return null;
		} else {
			HttpServletRequest request = servletRequestAttributes.getRequest();
			return (User) (request.getSession().getAttribute("currentUser"));
		}
	}
	
}
